#include <iostream>

using namespace std;
//定义图形类
class Shape
{
public:
	virtual void setColor()
	{
		cout<<"设置的颜色由具体的类决定"<<endl;
	}
	virtual void getArea()
	{
		
	}
	virtual void getGirth()
	{
		
	}
};

class Tirangle:public Shape  //三角形
{
public:
	Tirangle(int _w,int _h)
	{
		w=_w;
		h=_h;
	}
	virtual void setColor()
	{
		cout<<"红色"<<endl;
	}
	virtual void getArea()
	{
		cout<<w*h/2<<endl;
	}
	virtual void getGirth()
	{
		cout<<w<<endl;
	}
private:
	int w; //底
	int h; //高
};

class Rectangle:public Shape
{
public:
	Rectangle(int _w,int _h)
	{
		w=_w;
		h=_h;
	}
	virtual void setColor()
	{
		cout<<"白色"<<endl;
	}
	virtual void getArea()
	{
		cout<<w*h<<endl;
	}
	virtual void getGirth()
	{
		cout<<2*(w+h)<<endl;
	}
private:
	int w; //宽
	int h; //高	
};


void getAttr(Shape &shape)
{
	shape.setColor();
	shape.getArea();
	shape.getGirth();
}


int main()
{
	Tirangle tr(10,5);
	Rectangle rec(10,8);
	getAttr(tr);
	getAttr(rec);
}